package com.jvyou.app.ds.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jvyou.app.common.domain.model.PageResult;
import com.jvyou.app.common.utils.orm.WrapperTool;
import com.jvyou.app.ds.domain.dto.QuestionTypeDto;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jvyou.app.ds.domain.entity.QuestionType;
import com.jvyou.app.ds.service.QuestionTypeService;
import com.jvyou.app.ds.mapper.QuestionTypeMapper;

import java.util.Collections;
import java.util.List;


/**
 * 题目类型表(QuestionType)表服务实现类
 *
 * @author 橘柚
 * @since 2025-04-20 19:51:27
 */
@Service("questionTypeService")
public class QuestionTypeServiceImpl extends ServiceImpl<QuestionTypeMapper, QuestionType> implements QuestionTypeService {

    private QueryWrapper<QuestionType> getWrapper(QuestionTypeDto questionTypeDto){
        QueryWrapper<QuestionType> queryWrapper = new QueryWrapper<>();
        WrapperTool.notEmptyEq(queryWrapper, "name", questionTypeDto.getName());
        WrapperTool.notEmptyEq(queryWrapper, "code", questionTypeDto.getCode());
        WrapperTool.notEmptyEq(queryWrapper, "status", questionTypeDto.getStatus());
        return queryWrapper;
    }

    @Override
    public List<QuestionType> listQuestionType(QuestionTypeDto questionTypeDto) {
        return list(getWrapper(questionTypeDto));
    }

    @Override
    public PageResult<QuestionType> pageQuestionType(QuestionTypeDto questionTypeDto) {
        IPage<QuestionType> page = new Page<>(questionTypeDto.getCurrent(), questionTypeDto.getPageSize());
        page = page(page, getWrapper(questionTypeDto));
        return PageResult.success(page);
    }
}
